package morning.cat.study.jdk.externalizable;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Calendar;

import org.junit.Test;

public class DemoTest {

	@Test
	public void writeObject3() throws IOException {
		User3 user = new User3();
		user.setId(1003);
		user.setName("小猫");
		user.setAddDate(Calendar.getInstance().getTime());

		OutputStream outputStream = new FileOutputStream(new File("User3.out"));
		ObjectOutputStream oos = new ObjectOutputStream(outputStream);
		oos.writeObject(user);
		oos.close();
	}

	@Test
	public void readObject3() throws IOException, ClassNotFoundException {
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream("User3.out"));
		User3 user = (User3) ois.readObject();
		System.out.println(user);
		ois.close();
	}
}
